/**
 * Created by Richard Radlherr.
 * Date: 10.06.2006 12:03
 */

using System;
using TagTool.Core;
using System.Windows.Forms;
using TagTool.Devices;
using TagTool.Devices.Mouse;
using TagTool.GraphicTypes;

namespace TagTool.Nodes.Devices
{
	public class MouseNode : BaseNode
	{
		public static IMouseDevice mouse = WinMouse.GetInstance();

		// mouse coordinates
		private OutputSlot location;
		
		// button states
		private OutputSlot left;
		private OutputSlot middle;
		private OutputSlot right;
		
		public MouseNode() : base()
		{
			mouse.MouseDeviceEvent += new MouseDeviceEventHandler(OnMouseMove);
			location = new OutputSlot(this, "Location", typeof(PointD));
			location.Value = mouse.Location;

			left = new OutputSlot(this, "Left", typeof(bool));
			left.Value = mouse.Left;
			
			middle = new OutputSlot(this, "Middle", typeof(bool));
			middle.Value = mouse.Middle;
			
			right = new OutputSlot(this, "Right", typeof(bool));
			right.Value = mouse.Right;
			
			Name = "Mouse";
		}

		public void OnMouseMove(Object sender, MouseDeviceEventArgs e)
		{
			location.Value = e.Location;
		
			if (middle.Value == null || mouse.Middle != (bool)middle.Value)
			{
				middle.Value = mouse.Middle;
			}
			
			if (left.Value == null || mouse.Left != (bool)left.Value)
			{
				left.Value = mouse.Left;
			}
			
			if (right.Value == null || mouse.Right != (bool)right.Value)
			{
				right.Value = mouse.Right;
			}
			
			CastTrigger();
		}
		
		public override void Update(Object sender)
		{ // do nothing to update mouse Coordiantes
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot Location
		{
			get { return location; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot Left
		{
			get { return left; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot Middle
		{
			get { return middle; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot Right
		{
			get { return right; }
		}
		
	}
}
